1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import java.io.*;
33
34 public class WriteParams {
35 static int values[] = {Integer.MIN_VALUE, -1, 0, 1, 4, 16, 31,
36 32, 33, Integer.MAX_VALUE};
37 static char b[][] = {null, new char[32]};
38
39 static void test(Writer wtr) throws Exception {
40 int i = 0, j = 0, k = 0;
41 boolean nullPtr = false, indexOutBnd = false;
42
43 for (i = 0; i < b.length; i++) {
44 for ( j = 0; j < values.length; j++) {
45 for ( k = 0; k < values.length; k++) {
46
47 nullPtr = (b[i] == null);
48
49 int bufLen = nullPtr ? 0 : b[i].length;
50 indexOutBnd = ((values[j] + values[k]) < 0)
51 || (values[j] < 0)
52 || (values[j] > bufLen)
53 || (values[k] < 0)
54 || ((values[j] + values[k]) > bufLen);
55
56 try {
57 wtr.write(b[i], values[j], values[k]);
58 } catch (NullPointerException e) {
59 if (!nullPtr) {
60 throw new Exception
61 ("should not throw NullPointerException");
62 }
63 continue;
64 } catch (IndexOutOfBoundsException e) {
65 if (!indexOutBnd) {
66 throw new Exception
67 ("should not throw IndexOutOfBoundsException");
68 }
69 continue;
70 }
71
72 if (nullPtr || indexOutBnd) {
73 throw new Exception("Should have thrown an exception");
74 }
75 }
76 }
77 }
78 }
79
80 public static void main(String args[]) throws Exception{
81 StringWriter sw = new StringWriter();
82
83 test(sw);
84
85 test(new BufferedWriter(sw));
86
87 test(new CharArrayWriter());
88
89 test(new OutputStreamWriter(System.err));
90
91 test(new PipedWriter(new PipedReader()));
92 }
93 }